#容器类型  数据结构
#list    ---  数组（其他语言）
#list 特征：
#1、有序项目的集合
#2、里面可以存放任何类型对象
#3、可变数据类型
# a = ["a","b","c"]
# a[1] = 2
# print(a)
# print(a[1])
#
# lst1 = []
# if lst1:
#     print("ok")
# else:
#     print("error")
#
# lst2 = list()
# print(lst2)
#
# lst3 = list("abc")
# print(lst3)
#
# lst4 = [lst3, "aa", input]
# print(lst4)
# print(lst4[0][2])
#
# ##list基本用法
# #索引
# #下标从左至右，由0开始递增； 从右至左，下标从-1开始递减
# #print(lst3[3])
#
# #切片
# my_list = ["a","3","f","p","8"]
# print(my_list[1:3])
# print(my_list[::-1])
# print(my_list[-2:1:-1])
# print(my_list[4:-5:-1])
# print(my_list[2:-1:-1])


#slice对象
# lst1 = ["yt", "tl", "bxj","xyj","jgb"]
# slice1 = slice(0, 3, 1)
# lst2 = ["wuhong","shaseng","zhubajie","tangseng","guanyin"]
# print(lst1[slice1])
# print(lst1[0:3:1])
# print(lst2[slice1])

#练习
# lst3 = ['apple','orange', 123, 0.1111,'cali']
# print(lst3[1:])
# print(lst3[2:6])
# print(lst3[1:-2])
# print(lst3[0],lst3[-1])
# for i in lst3:
#     print(i)

####列表基本操作-增删改查

#增加
#append ： 在末尾，作为整体追加，类型不限
# lst1 = ["a","b","c"]
# lst1.append("x")
# print(lst1)

#insert:  在index位置插入数据,，可以插入任意数据类型
# lst1.insert(1, "y")
# print(lst1)
#
# #extend  ： 参数传递接收一个可迭代对象
# lst1.extend("123")
# print(lst1)
# lst1.extend(["aa","bb","cc"])
# print(lst1)
#
# # +
# print(lst1+["aa","bb","cc"])
#print(lst1 + "abc")


#删除
# lst1 = ["a", "b", "c", "a","x"]
#remove: 删除找到的第一个指定元素
# lst1.remove("a")
# print(lst1)
#列表里没有指定删除的元素，就会报错
#ValueError: list.remove(x): x not in list
#lst1.remove("f")

#pop
#删除元素，默认删除最后一个，也可以指定index删除
#返回被删除的元素
# result = lst1.pop()
# print(lst1)
# print(result)
# lst1.pop(1)
# print(lst1)

#clear: 清空
# lst1.clear()
# print(lst1)

#del  删除指定元素引用
# print(lst1)
# del lst1[0]
# print(lst1)
# del lst1[:3]
# print(lst1)


###修改
# 利用下标或者切片来进行修改
# lst1 = ["a","b","c","d","e","f"]
# lst1[0] = "x"
# print(lst1)
# print(lst1[1:1])
# lst1[1:2] = "qwe"
# print(lst1)
# print(lst1.count("e"))
# print(len(lst1))

##反转
#lst1 = lst1[::-1]
# print(lst1[::-1])
# lst1.reverse()  #对自身的操作
# print(lst1)

## 排序
#排序列表数据类型要一致
lst1 = ["a","你好","hello","test","tongle","快乐"]
# lst1.sort()  #对自身的操作
# lst1.sort(reverse=True)  #降序排序
# print(lst1)

# ## 统计
# print(len(lst1)) #统计总长度
# print(lst1.count("t")) #统计元素出现的次数
# print(lst1.index("test")) #查看元素下标，没有相应元素就会报错
#print(lst1.index("t"))

##拷贝
#copy
# >>> a = [1,2]
# >>> b = a
# >>> b.append(3)
# >>> b
# [1, 2, 3]
# >>> a
# [1, 2, 3]
# >>> a
# [1, 2, 3]
# >>> c = a.copy()
# >>> c.append(4)
# >>> c
# [1, 2, 3, 4]
# >>> a
# [1, 2, 3]
# >>> d = a[::]

#遍历
# for i in lst1:
#     print(i)
#
# for j in enumerate(lst1):
#     print(j)
#
# for i,j in enumerate(lst1):
#     print(i,"-->",j)

##判断成员关系
# in / not in
# print(lst1)
#
# print("b" in lst1)
# if "c" in lst1:
#     print("ok")
# else:
#     print("error")

s = ['python','Java','C']
s.append('我是追加')
print('追加后列表为:',s)
del s[0]
s.pop()
x = "cali"
print(x,"在" if x in s else "不在","列表里")
print('列表的长度:',len(s))
s2 = ['liu','cali',123,456]
s[1:1]=s2
#s.insert(1,s2)
print(s)